﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace ManagedScenarios
{
    [Browsable(false)]
    [Description("Creates a bunch of objects that are used to test basic dump parsing operations")]
    class BaseLibraryTypes : IScenario
    {
        // Set some value and reference types up on the instance (ie on the heap)

        public static int StaticIntField = 6000;
        [ThreadStatic]
        public static int ThreadStaticIntField = 61;

        public DateTime DateTime = DateTime.Now;
        public Uri Uri = new Uri("http://powerdbg.codeplex.com/");

        public void Run(string[] args)
        {
            // Set some value and reference types up as local variables 
            // value types will most likely be stored on the stack

            var someValueType = DateTimeOffset.Now.AddDays(1);
            var someReferenceType = new Uri("http://piers7.blogspot.com/");

            var arrayRefTypes = new[]
                               {
                                   new ADataStructure("Roberto", 1, true),
                                   new ADataStructure("Piers", 2, false),
                               };
            var dictionaryRefTypes = arrayRefTypes.ToDictionary(d => d.StringProperty);

            var hashtableRefTypes = new Hashtable(dictionaryRefTypes);
            var listRefTypes = new List<ADataStructure>(arrayRefTypes);

            // NB: None of the stack objects above will be GC'd
            // before the end of the scope *in a DEBUG build*
            // Put the GC.KeepAlive()'s back if we want to look at a Release build

            Console.WriteLine("Pausing for dump - press any key to continue");
            Console.ReadLine();
        }

        /// <summary>
        /// Just a class to show different ways of storing data within .net
        /// </summary>
        public class ADataStructure
        {
            private string _privateStringField;

            public string StringProperty
            {
                get { return _privateStringField; }
                set { _privateStringField = value; }
            }

            public int IntAutoProperty { get; set; }

            public bool IsEnabled;    // Public field

            public ADataStructure(string stringValue, int intValue, bool enabled)
            {
                _privateStringField = stringValue;
                IntAutoProperty = intValue;
                IsEnabled = enabled;
            }
        }
    }
}
